package Year22_Month07.day01;


import java.util.Scanner;

public class 连续最大和 {
    //滑动窗口
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }
        int nowMax = arr[0];
        int resMax = arr[0];
        for (int i = 1; i < arr.length; i++) {
            nowMax = Math.max(nowMax + arr[i],arr[i]);
            if(nowMax > resMax){
                resMax = nowMax;
            }
        }
        System.out.println(resMax);
    }
}
